package info.wangyuan.agent.service.curd.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import info.wangyuan.agent.entity.po.ProviderConfig;
import info.wangyuan.agent.exception.BusinessException;
import info.wangyuan.agent.mapper.ProviderMapper;
import info.wangyuan.agent.service.curd.ProviderService;
import org.springframework.stereotype.Service;

/**
 * 服务商配置服务
 *
 * @author Albert
 * @since 2025-09-04 22:19:24
 */
@Service
public class ProviderServiceImpl extends ServiceImpl<ProviderMapper, ProviderConfig> implements ProviderService {

    private final ProviderMapper providerMapper;

    public ProviderServiceImpl(ProviderMapper providerMapper) {
        this.providerMapper = providerMapper;
    }

    /**
     * 检查服务商配置是否被使用
     */
    @Override
    public void canDelete(Integer id) {
        ProviderConfig providerConfig = providerMapper.selectOne(Wrappers.lambdaQuery(ProviderConfig.class).eq(ProviderConfig::getId, id));
        if (providerConfig != null) {
            throw new BusinessException("该服务商配置正在被使用，无法删除");
        }
        removeById(id);
    }
}
